<!DOCTYPE html>
<html xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head lang="en">
    <meta charset="UTF-8">
    <title>考试管理</title>
    <link href="../resources/bootstrap/css/bootstrap.css" rel="stylesheet">
    <link href="../resources/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../resources/css/style.css" rel="stylesheet">
    <link href="../resources/css/exam.css" rel="stylesheet">

    <script type="text/javascript" src="../resources/js/jquery/jquery-3.1.1.min.js"></script>
    <script type="text/javascript" src="../resources/vue/vue.js"></script>
    <script type="text/javascript" src="../resources/vue/date.js"></script>
    <script type="text/javascript" src="../resources/bootstrap/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="../resources/js/all.js"></script>
    <script type="text/javascript" src="../resources/js/tag-list.js"></script>
    <script type="text/javascript" src="../resources/js/add-tag.js"></script>
    <script type="text/javascript" src="../resources/js/add-tag.js"></script>
    <script type="text/javascript" src="../resources/js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script type="text/javascript" src="../resources/laypage/laypage.js" charset="utf-8"></script>
    <script type="text/javascript" src="../resources/layui/layui.all.js" charset="utf-8"></script>
</head>
<body>
<header>

    <div class="logo">
        <h1>在线考试系统</h1>
    </div>
    <div class= "navbar bs-docs-nav" role="banner">
        <div class="container" style="margin: 0  264px ;">
            <ul class="nav navbar-nav">
                <li class="nav-tabs">
                    <a href="main.html" style="font-size: 1.2em; width: 135px;"><i
                            class="glyphicon glyphicon-home"></i>&nbsp;首页</a>
                </li>
                <li>
                    <a href="/view/question/question-list" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-list"></i>&nbsp;试题管理</a>
                </li>

                <li>
                    <a href="exampaper-list.html" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-list-alt"></i>&nbsp;试卷管理</a>
                </li>
                <li class="nav-tabs">
                    <a href="exam-list.html" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-indent-right"></i>&nbsp;考试管理</a>
                </li>
                <li>
                    <a href="/toUser.do" style="font-size: 1.2em;width: 130px;"><i
                            class="glyphicon glyphicon-user"></i>&nbsp;用户管理</a>
                </li>
                <li>
                    <a href="/toTag.do" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-random"></i>&nbsp;通用管理</a>
                </li>
                <li>
                    <a href="/toSystem.do" style="font-size: 1.2em;width: 132px;"><i
                            class="glyphicon glyphicon-cog"></i>&nbsp;系统设置</a>
                </li>
            </ul>
            <a href="/userLogout" style="position: absolute;right: 100px; top: 10px;"><i class=""></i>[注销]</a>
        </div>

    </div>
</header>

<div id="exam-content-left" style="width: 150px; position: relative ;left: 220px;">
    <ul class="nav nav-pills nav-stacked" style="font-size: 1.1em; margin-top: 100px; text-align: right;">

        <li class="active">
            <a> <i class="glyphicon glyphicon-th-list"></i> 考试管理 </a>
        </li>
        <li>
            <a href="exam-add.html"> <i class="glyphicon glyphicon-log-out"></i> 发布考试 </a>
        </li>
        <li >
            <a href="exampast_list.html"> <i class="glyphicon glyphicon-log-out"></i>考试历史 </a>
        </li>

    </ul>
</div>


<div class="container">
    <div class="col-xs-10" id="right-content">
        <div class="page-header">
        </div>
        <div id="app" class="container">
            <div class="table-responsive" style="width:1100px;">

                <form id="searchForm">
                    <div class="input-group search-form">
                        <input type="text" class="form-control" placeholder="考试名" id="examName" style="width: 100px;">&emsp;
                        <input type="text" class="form-control" placeholder="试卷" id="examPaper" style="width: 100px;">&emsp;
                        <input type="text" class="form-control" placeholder="创建人" id="user" style="width: 100px;">&emsp;
                        <input type="text" class="form-control" autocomplete="off" placeholder="起始时间" id="startTime" style="width: 200px;" readonly>&emsp;
                        <input type="text" class="form-control" autocomplete="off" placeholder="截止时间" id="endTime" style="width: 200px;" readonly>&emsp;
                        <span><label for="approved">状态:</label>
                <select class="select" id="approved" style="width: 100px;">
                    <option value="">全部</option>
                    <option value="0">待审核</option>
                    <option value="1">通过审核</option>
                    <option value="2">考试结束</option>
                </select>
            </span>&emsp;
                        <button class="btn btn-sm btn-info" type="button" id="btn-search">
                            <i class="fa fa-search"></i>搜索
                        </button>
                    </div>
                </form>
                <div class="page-content">
                    <div id="question-list">
                        <table class="table-striped table">
                            <thead>
                            <tr>
                                <td>序号</td>
                                <td>考试名称</td>
                                <td>试卷</td>
                                <td>创建人</td>
                                <td>起始时间</td>
                                <td>截止时间</td>
                                <td width="60px">备注</td>
                                <td>状态</td>
                                <td>操作</td>
                            </tr>
                            </thead>
                            <tbody>
                            <tr class="active" v-for="(item,index) in result">
                                <td>{{index+1}}</td>
                                <td>{{item.examName}}</td>
                                <td>{{item.examPaper.name}}</td>
                                <td>{{item.user.userName}}</td>
                                <td>{{item.startTime | DateFilter}}</td>
                                <td>{{item.endTime | DateFilter}}</td>
                                <td>
                                    <a tabindex="0" class="btn btn-sm btn-default examIntro" role="button" data-toggle="popover"
                                       data-trigger="focus" data-placement="top" v-bind:data-content="item.examIntro" @click="showInfo">
                                        查看
                                    </a>
                                </td>
                                <td>{{item.approved | StateFilter}}</td>
                                <td>
                                    <span class="r-reset-pwd-btn btn-sm btn-success" data-toggle="modal" data-target=".bs-example-modal-sm"
                                     @click="setId(item.id)">审核</span>
                                    <span class="r-update-btn btn-sm btn-warning" @click="getExamById(item.id)">修改</span>
                                    <span class="r-update-btn btn-sm btn-danger" @click="delExam(item.id)">删除</span>
                                </td>
                            </tr>
                            </tbody>
                            <tr align="center">
                                <td colspan="9">
                                    <div id="pagenav"></div>
                                </td>
                            </tr>
                        </table>
                        <div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel">
                            <div class="modal-dialog modal-sm" role="document">
                                <div class="modal-content">
                                    <div class="modal-header">
                                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
                                        <h4 class="modal-title" id="mySmallModalLabel">审核考试</h4>
                                    </div>
                                    <div class="modal-body">
                                        <div style="width: 150px; margin: 0 auto">
                                            <input type="hidden" id="aaa">
                                            <button class="btn btn-lg btn-success" onclick="updExamAudit(1)">
                                                通过
                                            </button>
                                            <button class="btn btn-lg btn-danger" onclick="updExamAudit(2)">
                                                拒绝
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="page-link-content">
                        <ul class="pagination pagination-sm"></ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<footer>
    <div class="container" style="width: 500px; margin: 0 auto;">
        <div class="row">
            <div class="col-md-12">
                <div class="copy">
                    <p>
                        ExamManage © <a href="javascript:void(0);" target="_blank">ExamManage</a> - <a
                            href="javascript:void(0);" target="_blank">主页</a> | <a href="javascript:void(0);"
                                                                                   target="_blank">关于我们</a>
                        | <a href="javascript:void(0);" target="_blank">FAQ</a> | <a
                            href="javascript:void(0);" target="_blank">联系我们</a>
                    </p>
                </div>
            </div>
        </div>
    </div>
</footer>
</body>
</html>
<script>
    Vue.filter("DateFilter", function (date) {
        var v = new Date(date);
        return formatDate(v, "yyyy-MM-dd HH:mm:ss");
    });
    Vue.filter("StateFilter", function (state) {
        if (state == 0) {
            return "待审核";
        } else if (state == 1) {
            return "通过审核";
        } else {
            return "考试结束";
        }
    });

    $(function () {
        //时间选择
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //日期时间选择器
            laydate.render({
                elem: '#startTime'
                , type: 'datetime'
            });
        })

        layui.use('laydate', function () {
            var laydate = layui.laydate;
            //日期时间选择器
            laydate.render({
                elem: '#endTime'
                , type: 'datetime'
            });
        })

    });

    var app = new Vue({
        el: "#app",
        data: {
            result: []
        }
    });
    var getAllExamByPage = function (curr) {
        $.ajax({
            type: 'POST',
            url: '/getExamByPage',
            dataType: 'json',
            data: {
                pageSize: 10,
                currPage: curr || 1,
                examName: $("#examName").val(),
                approved: $("#approved").val(),
                starttime: $("#startTime").val(),
                endtime: $("#endTime").val(),
                exampaper: $("#examPaper").val(),
                username: $("#user").val()
            },
            success: function (msg) {
                app.result = msg.page;
                laypage({
                    cont: 'pagenav',  //分页容器
                    pages: msg.totalPage, //总页数
                    skin: '#333333',
                    first: '第一页',
                    last: '最后一页',
                    curr: curr || 1,
                    jump: function (obj, first) {
                        if (!first) {
                            getAllExamByPage(obj.curr);
                        }
                    }
                });
            }
        });
    };
    getAllExamByPage();

    $("#btn-search").click(function () {
        getAllExamByPage();
    });

    var showInfo = function (btn) {
        var v = btn.target;
        $(v).popover("show");
    };

    var updExamAudit = function (approved) {
        $.ajax({
            type: "POST",
            url: "/updExamAudit",
            data: {
                id: examId,
                approved: approved
            },
            success: function (data) {
                if (data > 0) {
                    getAllExamByPage();
                }
                $(".close").click();
            }, error: function () {
                //alert("异常")
            }
        });
    };

    var examId;
    var setId = function (id) {
        examId = id;
    }

    var getExamById = function (id) {
        layer.open({
            type: 2,
            title: '修改信息',
            fix: false,
            maxmin: true,
            shadeClose: true,
            area: ['100%', '100%'],
            content: '/getExamById?id='+id,
            end: function () {
                getAllExamByPage();
            }
        });
    }

    var delExam = function (id) {
        layer.confirm('确认删除？', {
            btn: ['是', '否']
        }, function () {
            $.ajax({
                type: 'GET',
                dataType: 'JSON',
                url: '/delExam',
                data: {
                    id: id
                },
                success: function (data) {
                    if(data > 0){
                        getAllExamByPage();
                        layer.msg('成功', {icon: 6});
                    }else {
                        layer.msg('失败', {icon: 3});
                    }
                },error:function () {
                    layer.msg("该考试正在进行,不允许删除")
                }
            });
        }, function () {

        });
    }
</script>